package com.medical.app.mapper;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.medical.app.entity.Hospital;

import java.util.List;

public interface HospitalMapper extends BaseMapper<Hospital> {
    default Hospital findByHospitalName(String hospitalName){
        LambdaQueryWrapper<Hospital> queryWrapper = new LambdaQueryWrapper<Hospital>().eq(Hospital::getHospitalName,hospitalName);
        return this.selectOne(queryWrapper);
    };

     default Page<Hospital> page(String hospitalName,int pageNum,int pageSize){
        Page<Hospital> page = new Page<>(pageNum, pageSize);
        LambdaQueryWrapper<Hospital> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.like(hospitalName!=null, Hospital::getHospitalName,hospitalName);
        return this.selectPage(page,queryWrapper);
    };

    default List<Hospital> selectHospitals(){
        LambdaQueryWrapper<Hospital> queryWrapper = new LambdaQueryWrapper<>();
        return this.selectList(queryWrapper);
    };

    default Hospital selectHospital(Long hospitalId){
        LambdaQueryWrapper<Hospital> queryWrapper = new LambdaQueryWrapper<Hospital>().eq(Hospital::getHospitalId,hospitalId);
        return this.selectOne(queryWrapper);
    };
}